package pers.qianyu.month_202102.date_20210206;

/**
 * 1423. 可获得的最大点数
 * https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/
 *
 * @author mizzle rain
 * @date 2021-02-06 11:10
 */
public class MaxScore {
    public int maxScore(int[] nums, int k) {
        if (k >= nums.length) {
            int s = 0;
            for (int x : nums) s += x;
            return s;
        }
        int sum = 0, min = Integer.MAX_VALUE;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
            if (nums.length - k - 1 <= i) {
                min = Math.min(min, sum);
                sum -= nums[i - (nums.length - k - 1)];
            }
        }
        sum = 0;
        for (int x : nums) sum += x;
        return sum - min;
    }

    public static void main(String[] args) {
        int result = new MaxScore().maxScore(new int[]{9, 7, 7, 9, 7, 7, 9}, 7);
        System.out.println("result = " + result);
    }
}
